from django.db import models

from users.models import User


# Create your models here.

class Article(models.Model):
    content = models.TextField(verbose_name='文章内容')
    article_imgs = models.CharField(max_length=1024, null=True, blank=True, verbose_name='文章图片')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    is_show = models.BooleanField(default=True, verbose_name='是否匿名')
    add_love = models.IntegerField(default=0, verbose_name='点赞数')
    add_collect = models.IntegerField(default=0, verbose_name='收藏数')
    add_comment = models.IntegerField(default=0, verbose_name='评论数')
    is_active = models.BooleanField(default=True, verbose_name='是否激活')  # 文章是否激活
    user = models.ForeignKey(User, related_name='articles_list', on_delete=models.CASCADE, verbose_name='作者')

    class Meta:
        verbose_name = '用户文章'
        verbose_name_plural = verbose_name

class Collect(models.Model):
    user = models.ForeignKey(User, related_name='collect_list', on_delete=models.CASCADE, verbose_name='用户收藏')
    article = models.ForeignKey(Article, related_name='collect_list', on_delete=models.CASCADE, verbose_name='文章收藏')

    class Meta:
        verbose_name = '用户收藏'
        verbose_name_plural = verbose_name
        db_table = 'articles_collect'

class Comment(models.Model):
    content = models.TextField(verbose_name='评论内容')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    add_love = models.IntegerField(default=0, verbose_name='点赞数')
    user = models.ForeignKey(User, related_name='comment_list', on_delete=models.CASCADE, verbose_name='评论者')
    is_active = models.BooleanField(default=True, verbose_name='是否激活')
    level = models.IntegerField(default=0, verbose_name='评论层级')   # 评论层级
    comment = models.ForeignKey('self', related_name='reply_list', on_delete=models.CASCADE, verbose_name='父评论')
    article = models.ForeignKey(Article, related_name='comment_list', on_delete=models.CASCADE, verbose_name='评论文章')

    class Meta:
        verbose_name = '用户评论'
        verbose_name_plural = verbose_name
        db_table = 'articles_comment'
